#pragma once
#include <string>
#include <mutex>
#include <memory>
#include <map>
#include <thread>
#include "mosquitto.h"
namespace Planner
{
class MqttPlannerServer
{
    public:
        MqttPlannerServer(const MqttPlannerServer&)=delete;
        MqttPlannerServer(const MqttPlannerServer&&)=delete;
        MqttPlannerServer& operator=(const MqttPlannerServer&)=delete;
        MqttPlannerServer& operator=(const MqttPlannerServer&&)=delete;
        static std::shared_ptr<MqttPlannerServer> getInstance();
        void startMqtt();
		bool init();
		void mqttDisconnect();
        void pubPathMsg(int id,const std::string& msg_json);
    private:
        MqttPlannerServer();
        bool getLocalIP();
        //callback function
        static void subscribeCallback(struct mosquitto* mosq, void* obj, int msg_id, int qos_count, const int* granted_qos);
        static void connectCallback(struct mosquitto* mosq, void* obj, int response);
        static void messageCallback(struct mosquitto* mosq, void* obj, const struct mosquitto_message* msg);
        static void disconnectCallback(struct mosquitto *mosq, void *obj, int rc);
		struct mosquitto *_mosq = NULL;
		bool _mqtt_is_connected=false;
		
        std::string _local_ip;
        std::string _mqtt_username;
        std::string _mqtt_password;
        static std::shared_ptr<MqttPlannerServer> _singleton_instance;
};
};